package com.java.module.fire.controller.api;

import com.java.common.lang.annotation.Log;
import com.java.common.lang.domain.AjaxResult;
import com.java.common.lang.enums.BusinessTypeEnum;
import com.java.common.service.ApiTokenService;
import com.java.common.utils.WebKit;
import com.java.module.fire.domain.Comment;
import com.java.module.fire.domain.Post;
import com.java.module.fire.service.IPostService;
import jodd.jtx.meta.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.java.module.fire.service.ICommentService;

/**
 * 帖子评论Controller
 * 
 * @author Administrator
 * @date 2025-02-10
 */
@RestController("ApiCommentController")
@RequestMapping("/fire/comment")
public class CommentController {

    @Autowired
    ICommentService commentService;


    @Autowired
    ApiTokenService apiTokenService;

    @Autowired
    IPostService postService;


    /**
     * 新增帖子评论
     */
    @Log(title = "帖子评论", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @Transaction
    public AjaxResult add(@RequestBody Comment comment) {
        comment.setUid(apiTokenService.getLoginUserId());
        commentService.insertComment(comment);
        Post post = new Post();
        post.setPostId(comment.getPostId());
        post.setManualCount(1L);
        postService.addManualCount(post);
        return AjaxResult.success("评价成功");
    }

}